//
//  WZLReadCollectionViewCell.m
//  MapleLeaf
//
//  Created by WangZe on 15/12/4.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "WZLReadCollectionViewCell.h"

@implementation WZLReadCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
        
    }
    return self;
}
- (void)createView
{
    self.ScrollView = [[UIScrollView alloc] init];
    [self.contentView addSubview:self.ScrollView];
    self.ScrollView.backgroundColor = [UIColor blackColor];
    self.ScrollView.showsHorizontalScrollIndicator = NO;
    self.ScrollView.showsVerticalScrollIndicator = NO;
    [self.ScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(self.contentView.mas_left, 0);
        Top(self.contentView.mas_top, 0);
        Right(self.contentView.mas_right, 0);
        Bottom(self.contentView.mas_bottom, 0);
    }];
    
    self.picImageView = [[BaseReadImageView alloc] init];
    [self.ScrollView addSubview:self.picImageView];
}
- (void)setStr:(NSString *)str
{
    if (_str != str) {
        _str = str;
    }

}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:self.str] placeholderImage:[UIImage imageNamed:@"123.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
       self.h = self.ScrollView.frame.size.width * image.size.height / (image.size.width + 0.01);
        if (self.str) {
            
            self.ScrollView.contentOffset = CGPointMake(0, 0);
        if (_h > HEIGHT) {
            
            
            
            self.picImageView.frame = CGRectMake(0, 60, WIDTH, _h);
            self.ScrollView.contentSize = CGSizeMake(0, _h + 100);

            NSLog(@"%f", _h);
            NSLog(@"%f", self.ScrollView.contentSize.height);
        }
        else
        {
            [self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                Left(self.contentView.mas_left, 0);
                Top(self.ScrollView.mas_top, 50);
                Right(self.contentView.mas_right, 0);
                HequalNum(HEIGHT - 100);
            }];
            _h = HEIGHT - 100;
            
        }
        }
    }];
    // 4.捏合
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [self.picImageView addGestureRecognizer:pinch];
    
    
}

- (void)pinchAction:(UIPinchGestureRecognizer *)pinch
{
//    UIImageView *imageView = (UIImageView *)pinch.view;
//    static CGFloat d = 1;
//    if (d <= 1) {
//        if (d >= 0.5) {
//            // Scale比例 按照比例来进行缩放
//            imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
//            //        NSLog(@"%g", pinch.scale);
//            pinch.scale = 1;
//            d = imageView.frame.size.height / _h;
//            NSLog(@"%f" , d);
//        }
//        else
//        {
//            pinch.scale = 1;
//            
//        }
//    }
    
}

@end
